import {PluginCommand} from "./PluginCommand";
import {
  PluginCADToolFunctionType,
  PluginEventType,
  PluginFunctionType
} from "../../nodeApp/static/lib/crowncad-plugin-sdk-0.0.1";

class MassDistributionCheckCommand extends PluginCommand{
  constructor() {
    super();
  }

  handlePickInstance(cb){
    this.event.subscribeInstancePickEvent(res => (
      cb(res.instance)
    ));
  }

  getMassAttributeInfo(attributeParams,cb){
    if (this.toolQuery) {
      this.toolQuery.getMassAttributeInfo(attributeParams).then(res => {
        cb(res.data.attributeInfos);
      });
    }
  }

  massCoverConfirm(massCoverParams){
    if (this.request) {
      this.request.execFunction(PluginCADToolFunctionType.MASSCOVERCONFIRM, {massCoverParams}).then(
      );
    }
  }

  massCoverReSet(massCoverParams){
    if (this.request) {
      this.request.execFunction(PluginCADToolFunctionType.MASSCOVERRESET, {massCoverParams}).then(
      );
    }
  }

  clearHighLightInstanceElement(paramId) {
    if (this.request) {
      this.request.execFunction(PluginFunctionType.CLEARHIGHLIGHTINSTANCEELEMENT, {paramId});
    }
  }

  getInstanceTree(cb) {
    if(this.query) {
      this.query.getInstanceTree().then(res => {
        cb(res?.data?.instanceTree);
      });
    }
  }

  getInstanceProtoRefByInstanceId(params, cb) {
    if (this.toolQuery) {
      this.toolQuery.getInstanceProtoRefByInstanceId(params).then(res => {
        cb(res.data.instance);
      });
    }
  }
}

const massDistributionCheckCommand = new MassDistributionCheckCommand();
export {massDistributionCheckCommand};
